/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model.DAO;

import Model.Beans.Institution;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Eduardo
 */
public class InstitutionDAO extends AbstracDAO<Institution> {
    
    public Institution getInstitution(Institution inst) {
        
        session = HibernateUtil.getSessionFactory().openSession();
        Criteria institutionCri = session.createCriteria(Institution.class);

        institutionCri.setFetchMode("user", FetchMode.JOIN);
        institutionCri.add(Restrictions.eq("user.iduser", inst.getUser().getIduser()));

        List<Institution> institutions = null;
        institutions = institutionCri.list();
        
        if(!institutions.isEmpty())
        {
           
            return institutions.get(0);
        }
         
        session.close();
        return null;
}

    public List<Institution> buscarInstitution(String institutionId) {
        session = HibernateUtil.getSessionFactory().openSession();
        Criteria studentCri = session.createCriteria(Institution.class);
        
        studentCri.setFetchMode("user", FetchMode.JOIN);
        
        Criteria userCri = studentCri.createCriteria("user");
        userCri.add(Restrictions.eq("iduser", Integer.parseInt(institutionId)));
        
        List<Institution> students = studentCri.list();
        session.close();
        return students;
    }
    
}
